package com.rose.doorto.footbathpay.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 使用springsession管理session。使用redis存储会话信息
 * @Author 李庆超
 * @email 1481791489@qq.com
 * @Package：com.rose.doorto.footbathdoor.config
 * @Project：door-to-door
 * @name：DoorSessionConfig
 * @date 2024/07/30 2024/7/30:10:15:
 */
@EnableRedisHttpSession
@Configuration
public class DoorSessionConfig {

    /**
     * 自定义服务器返回给浏览器的cookie设置
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        //设置cookie名字
        serializer.setCookieName("DOORSESSION");
        //默认cookie有效域是当前域,比如访问xxxx.door.com服务器返回的cookie数据的有效域就是xxxx.door.com
//        serializer.setDomainName("xxxx.door.com");
        return serializer;
    }

    /**
     * 序列化机制选择json格式,默认使用jdk序列化,所以要保存的对象都要实现Serializable接口
     * @return
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }

}
